from django.shortcuts import render
from rest_framework import viewsets
from rest_framework.pagination import PageNumberPagination

from goods.models import GoodsCategory, SKU, SPUSpecification, SPU
# Create your views here.
from goods.serializers import GoodsCategorySerializer, SKUSerializer, SPUSpecificationSerializer, SPUSerializer


class PageNum(PageNumberPagination):
    page_size_query_param = 'page_size'
    page_size = 5


# 商品分类
class GoodsCategoryModelViewSet(viewsets.ModelViewSet):
    queryset = GoodsCategory.objects.all()
    serializer_class = GoodsCategorySerializer


# sku
class SKUModelViewSet(viewsets.ModelViewSet):
    queryset = SKU.objects.all()
    serializer_class = SKUSerializer

    pagination_class = PageNum

    filter_fields = ('category',)

    # http://127.0.0.1:8000/sku/?category=115


# spu的规格
class SPUSpecificationModelViewSet(viewsets.ModelViewSet):
    queryset = SPUSpecification.objects.all()
    serializer_class = SPUSpecificationSerializer

    filter_fields = ('spu',)

    # http://127.0.0.1:8000/spuspec/?spu=1


# spu
class SPUModelViewSet(viewsets.ModelViewSet):
    queryset = SPU.objects.all()
    serializer_class = SPUSerializer

    filter_fields = ('id', 'sku')
